package com.yixun.qfbao.hander;

import com.yixun.qfbao.api.service.PersonnelService;
import com.yixun.qfbao.apidto.ForbiddenOrNotPartnerReqDto;
import com.yixun.qfbao.apidto.ForbiddenOrNotPartnerResDto;
import com.yixun.qfbao.dto.base.BaseRequestDTO;
import com.yixun.qfbao.dto.base.BaseResponseDTO;
import com.yixun.qfbao.hander.base.CommonAbstractHander;
import com.yixun.qfbao.model.enums.PartnerInfoEnum;
import com.yixun.qfbao.utils.LoginUtils;
import com.yixun.qfbao.vo.ForbiddenOrNotPartnerReqVo;
import com.yixun.qfbao.xf.model.enums.ResultEnum;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

/**
 * @Description
 * @Date 2017/11/23
 * @Author sangtao
 * @Computer Administrator
 */
@Service("forbiddenOrNotPartnerHander")
public class ForbiddenOrNotPartnerHander extends CommonAbstractHander {
    private static Logger logger= LoggerFactory.getLogger(ForbiddenOrNotPartnerHander.class);
    @Autowired
    PersonnelService personnelService;
    @Autowired
    LoginUtils loginUtils;
    @Override
    public BaseResponseDTO doBusiness(BaseRequestDTO reqDto) {
        ForbiddenOrNotPartnerReqVo req = (ForbiddenOrNotPartnerReqVo)reqDto;
        ForbiddenOrNotPartnerReqDto forbiddenOrNotPartnerReqDto = req.getParams();
        BaseResponseDTO<ForbiddenOrNotPartnerResDto> res = new BaseResponseDTO<ForbiddenOrNotPartnerResDto>();
        ForbiddenOrNotPartnerResDto resDto = new ForbiddenOrNotPartnerResDto();
        try{
            resDto = personnelService.forbiddenOrNotPartner(forbiddenOrNotPartnerReqDto);
            if(ResultEnum.SUCCESS.getNo().equals(resDto.getResult()) && PartnerInfoEnum.STATUS_ENABLE.getCode().equals(forbiddenOrNotPartnerReqDto.getStatus())){
                //loginUtils.clearCacheForH5(forbiddenOrNotPartnerReqDto.getId());
                loginUtils.removeUser(forbiddenOrNotPartnerReqDto.getId());
            }
        } catch (Exception e) {
            logger.error("ForbiddenOrNotPartnerHander error: {}", e);
            resDto.setResult(ResultEnum.FAIL.getNo());
            resDto.setResultMsg("编辑人员失败!");
        }
        res.setResData(resDto);
        res.setResult(resDto.getResult());
        return res;
    }
}
